package com.example.androiddev.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.androiddev.R;
import com.example.androiddev.adapter.PersonAdapter;
import com.example.androiddev.base.BaseActivity;
import com.example.httplib.bean.Person;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zxw.
 * CreateDate: 2019/12/19 9:22
 * Description: 页面描述
 */
public class QuickAdapterActivity extends BaseActivity {

    private static final String TAG = "QuickAdapterActivity";

    /**
     * SwipeRefreshLayout
     */
    private SwipeRefreshLayout refreshLayout;
    /**
     * RecyclerView
     */
    private RecyclerView recyclerView;

    /**
     * adapter
     */
    private PersonAdapter adapter;

    /**
     * 数据源
     */
    private List<Person> datas = new ArrayList<>();

    private Context context = QuickAdapterActivity.this;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    /**
     * 加载数据
     */
    @Override
    protected void initData() {
        for (int i = 0; i < 50; i++) {
            Person person = new Person(String.valueOf(i + 7), "张三" + i);
            datas.add(person);
        }
        adapter.notifyDataSetChanged();
    }

    @Override
    protected int getContentView() {
        return R.layout.activity_quick_adapter_layout;
    }

    /**
     * 初始化view
     */
    @Override
    protected void initView() {
        super.initView();
        setTitle(TAG);
        recyclerView = findViewById(R.id.recycleView);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(linearLayoutManager);
        adapter = new PersonAdapter(datas);
        recyclerView.setAdapter(adapter);
        adapter.setOnItemChildClickListener((adapter, view, position) -> {
            switch (view.getId()) {
                case R.id.name:
                    Toast.makeText(context, datas.get(position).getName(), Toast.LENGTH_SHORT).show();
                    break;
                case R.id.age:
                    Toast.makeText(context, datas.get(position).getAge(), Toast.LENGTH_SHORT).show();
                    break;
                default:
                    break;
            }
        });

        adapter.setOnItemClickListener((adapter, view, position) -> {

        });


    }
}
